import {request} from "@umijs/max";
import {ResponseStructure} from "@/requestErrorConfig";
import {API, DynamicObject, PageParams} from "@/services/typings";
import {ParamsType} from "@ant-design/pro-components";
import {listData, pageData} from "@/services/base-request";


export async function pageUser(params: PageParams, options?: { [key: string]: any },) {
  return pageData('/user', params, options)
}

export async function updateUserById(data: API.CurrentUser, options?: { [key: string]: any },) {
  return request<ResponseStructure>('/api/user/updateById', {
    method: 'PUT',
    data,
    ...(options || {}),
  });
}

export async function deleteUserById(id: string | number, options?: { [key: string]: any },) {
  return request<ResponseStructure>(`/api/user/${id}`, {
    method: 'DELETE',
    ...(options || {}),
  });
}

export async function addUser(data: API.CurrentUser, options?: DynamicObject,) {
  return request<ResponseStructure>('/api/user', {
    method: 'POST',
    data,
    ...(options || {}),
  });
}

export const listUserAPI = (params: ParamsType) => {
  return listData("/user", params)
}

